﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using AspNetCs.Bll;
using AspNetCs.Common;
using AspNetCs.Model;
using System.Data;
public partial class Script_Cemetery_load : BasePage
{
    protected int id = 0;
    protected Cemetery_Model CemeteryMd = new Cemetery_Model();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
            CemeteryMd = Cemetery_Bll.CreateNew.GetModel(id);
        }
        catch
        {
            id = 0;
        }
    }
    protected string Js()
    {
        string str = "";
        try
        {
            List<Cemetery_AddNumId_Model> list = Cemetery_AddNumId_Bll.CreateNew.GetData(" cemeteryId=" + id + " and UserId=" + CemeteryMd.CreateId);

            Response.Write("function loadMemorial(){");//alert(SetTop);
            foreach (Cemetery_AddNumId_Model md in list)
            {
                Response.Write("var speed = 500;");
                Response.Write("var ModifyDiv = \"<div id='ModifyDidvcontent' style='display:none; position:absolute; top:0px; left:0px; border-style:solid; border-color:#000000; border-width:1px; background-color:#FFFFFF; width: 252px;height:80px;border:1px solid #666666;padding:5px;'z-index='110'></div>\";");
                Response.Write("var picdivLeft=parseInt($('#EditDiv').offset().left);");//当前图片的left
                Response.Write("var picdivTop=parseInt($('#EditDiv').offset().top);");//当前图片的Top
                Response.Write("var SetTop=picdivTop+" + md.PositionY + ";");//alert(SetTop);
                Response.Write("var Setleft=picdivLeft+" + md.PositionX + ";");//alert(Setleft);
                DataTable MemorialTb = Memorial_Bll.CreateNew.GetDataTable(" Where Numid='" + md.NumId + "'");
                if (MemorialTb.Rows.Count > 0)
                {
                    Response.Write("var memorialDiv=\"<img alt='纪念馆馆号：" + md.NumId + "' id='memorial" + md.PositionX + md.PositionY + "' src='" + configInfo.SiteUrl + "images/icon-mu.jpg' border='0' width='15px' height='15px' style='position:absolute;top:0px;left:0px;cursor:hand;' >\";");
                }
                else
                {
                    Response.Write("var memorialDiv=\"<img id='memorial" + md.PositionX + md.PositionY + "' src='" + configInfo.SiteUrl + "images/icon-mu1.jpg' border='0' width='15px' height='15px' style='position:absolute;top:0px;left:0px;cursor:hand;' >\";");
                }
                Response.Write("$(document.body).append(memorialDiv);");
                Response.Write("$(\"#memorial" + md.PositionX + md.PositionY + "\").css('top',(SetTop-8)+'px');");
                Response.Write("$(\"#memorial" + md.PositionX + md.PositionY + "\").css('left',(Setleft-8)+'px');");


                #region 点击墓的图片时触发

                Response.Write("$(\"#memorial" + md.PositionX + md.PositionY + "\").bind('click',function(e){");

                if (Base_GetLoginInfo.GetUserID <= 0)
                {
                    Response.Write("location.href='default.aspx'");
                }
                else
                {

                    if (Base_GetLoginInfo.GetUserID == CemeteryMd.CreateId)
                    {



                        Response.Write("$(document.body).append(ModifyDiv);");
                        ContentDiv(md);
                        Response.Write("$('#ModifyDidvcontent').html(ContentDiv);");
                        Response.Write("var thisDivH=$(\"#ModifyDidvcontent\").height();");
                        Response.Write("var thisDivW=$(\"#ModifyDidvcontent\").width();");
                        Response.Write("var PageH = getTotalHeight();");
                        Response.Write("var PageW = getTotalWidth();");
                        Response.Write("var EndLeft=((picdivLeft+" + md.PositionX + "));");
                        Response.Write("var EndTop=((picdivTop+" + md.PositionY + "));");
                        Response.Write("if(EndTop+thisDivH>=PageH){");
                        Response.Write("EndTop=EndTop-thisDivH;");
                        Response.Write("}");
                        Response.Write("if(EndLeft+thisDivW>=PageW){");
                        Response.Write("EndLeft=EndLeft-thisDivW-8;");
                        Response.Write("}");
                        Response.Write("else{");
                        Response.Write("EndLeft=EndLeft;");
                        Response.Write("}");


                        Response.Write("$(\"#ModifyDidvcontent\").show(speed);");
                        Response.Write("$(\"#ModifyDidvcontent\").css({\"top\":EndTop+'px'});");
                        Response.Write("$(\"#ModifyDidvcontent\").css({\"left\":EndLeft+'px'});");
                        Response.Write("$(\"#ModifyDidvcontent\").css({\"display\": \"block\"});");
                        Response.Write("if($(\"#AddDidvcontent\").length>0){$(\"#AddDidvcontent\").fadeOut(speed);};");
                        Response.Write("if($(\"#AddDivNew\").length>0){$(\"#AddDivNew\").fadeOut(speed);};");

                        #region 绑定取消按钮

                        Response.Write("$(\"#closethis\").bind(\"click\",function(e){$(\"#ModifyDidvcontent\").remove();});");

                        #endregion

                        #region 绑定删除事件

                        Response.Write("$(\"#delnum\").bind(\"click\",function(e){");

                        #region 删除
                        Response.Write("if(confirm('是否真的需要删除它吗？')){");
                        Response.Write(" $.ajax({");
                        Response.Write("url:'" + configInfo.InstallDir + "AjaxXml/delete_Cemetery_AddNumId.aspx',");
                        Response.Write("type: 'POST',");
                        Response.Write("dataType: 'html',");
                        Response.Write("beforeSend:function(){");
                        Response.Write("$(\"#ModifyAlt\").html(\"&nbsp;<img src='" + configInfo.InstallDir + "images/027.gif' align='absmiddle' >&nbsp;加载中....\");");
                        Response.Write("},");
                        Response.Write("data:'id=" + md.Id + "',");

                        Response.Write("error: function(html){");
                        Response.Write(" $(\"#ModifyAlt\").html(\"**出错了!\");");
                        Response.Write("},");

                        Response.Write("success: function(html){");
                        Response.Write("if(html=='no'){alert('参数出错!');}");
                        Response.Write("else if(html=='-1'){alert('删除失败!');}");
                        Response.Write("else{alert('删除成功!');$(\"#ModifyDidvcontent\").remove();$(\"#memorial" + md.PositionX + md.PositionY + "\").remove();}");
                        // Response.Write("else{alert('删除成功!');}");
                        Response.Write("}");

                        Response.Write("});");

                        Response.Write("}");

                        #endregion

                        Response.Write("});");

                        #endregion

                        #region 绑定修改事件

                        Response.Write("$(\"#Modifybtn\").bind(\"click\",function(e){");

                        Response.Write("var CemeNumValue=$('#ly_cemetery').val();");
                        Response.Write("var lyname=$('#lyname').val();");

                        #region 修改

                        Response.Write(" $.ajax({");
                        Response.Write("url:'" + configInfo.InstallDir + "AjaxXml/Update_Cemetery_AddNumid.aspx',");
                        Response.Write("type: 'POST',");
                        Response.Write("dataType: 'html',");
                        Response.Write("beforeSend:function(){");
                        Response.Write("$(\"#ModifyAlt\").html(\"&nbsp;<img src='" + configInfo.InstallDir + "images/027.gif' align='absmiddle' >&nbsp;加载中....\");");
                        Response.Write("},");


                        Response.Write("data:'id=" + md.Id + "&lyid=" + id + "&CemeNumValue='+CemeNumValue+'&lyname='+lyname,");


                        Response.Write("error: function(html){");
                        Response.Write(" $(\"#ModifyAlt\").html(\"**请正确填写您创建的纪念馆馆号,以便访问!\");");
                        Response.Write("},");


                        Response.Write("success: function(html){");
                        Response.Write("if(html==-1){$(\"#ModifyAlt\").html(\"纪念馆馆号只能全部为数字\");}");
                        Response.Write("else if(html==-2){$(\"#ModifyAlt\").html(\"当前陵园不存在\");}");
                        Response.Write("else if(html==-3){$(\"#ModifyAlt\").html(\"当前所对应的墓点已经不存在，请刷新后重试\");}");
                        Response.Write("else if(html==-4){$(\"#ModifyAlt\").html(\"当前输入的纪念馆号不存在\");}");
                        Response.Write("else if(html==-5){$(\"#ModifyAlt\").html(\"当前输入的纪念馆号已经在当前页面存在\");}");

                        Response.Write("else{alert('修改成功!');location.reload();}");
                        Response.Write("}");


                        Response.Write("});");
                        #endregion

                        Response.Write("});");

                        #endregion


                    }
                }
                Response.Write(" });");
                #endregion


            }
            Response.Write("}");//alert(SetTop);
        }
        catch
        {
            str = "";
        }
        return str;
    }

    protected void ContentDiv(Cemetery_AddNumId_Model md)
    {
        Cemetery_Model CemeMd = Cemetery_Bll.CreateNew.GetModel(md.CemeteryId);
        Response.Write("var ContentDiv=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;陵园编号：<input id='lynum' name='lynum'  type='text' value='" + CemeMd.Numid + "'  disabled='disabled' title='无法修改' style='border:1px solid #efefef;height:22px;width:140px;'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;陵园名称：<input id='lyname' name='lyname'  type='text' value='" + CemeMd.Names + "' style='border:1px solid #efefef;height:22px;width:140px;' ><br>对应的纪念馆：<input id='ly_cemetery' name='ly_cemetery' value='" + md.NumId + "'  type='text' style='border:1px solid #efefef;height:22px;width:140px;' ><br><span style='color:red;' id='ModifyAlt'>*请正确填写您创建的纪念馆馆号,以便访问!</span><br><input id='Modifybtn' type='button' value='修改'  />&nbsp;&nbsp;<input id='closethis' name='closethis'  type='button' value='取消'  />&nbsp;&nbsp;<input id='delnum' type='button' value='删除'  />\";");





    }


}
